package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark8Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark8 extends BaseMark {

    LayoutWatermark8Binding binding;

    public Mark8(@NonNull Context context) {
        super(context);
    }

    public Mark8(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark8(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark8Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark8Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding1, binding.binding3, binding.binding11, binding.binding13, binding.binding15);
        }
    }

    @Override
    public void update() {
        setText(binding.binding2, "time8", "13:30", binding.binding1);
        setTime(binding.binding2, new SimpleDateFormat("HH:mm"));
        setText(binding.binding4, "phone8", "133****9863", binding.binding3);

        String[] ss = new EditItem("jingwei8").getStringPoints();
        setText(binding.binding6, "jingwei8", "117.2985642", binding.binding5);
        binding.binding6.setText(ss[1]);
        binding.binding8.setText(ss[0]);

        setText(binding.binding10, "didian8", "在这里", binding.binding9);
        setText(binding.binding12, "haiba8", "1234米", binding.binding11);
        setText(binding.binding14, "weather8", "晴", binding.binding13);
        setText(binding.binding16, "beizhu8", binding.binding15);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time8", "时间", true));
        list.add(new EditItem("phone8", "手机"));
        list.add(new EditItem("jingwei8", "经纬度"));
        list.add(new EditItem("didian8", "地点"));
        list.add(new EditItem("haiba8", "海拔"));
        list.add(new EditItem("weather8", "天气"));
        list.add(new EditItem("beizhu8", "备注"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding2, new SimpleDateFormat("HH:mm"));
        } else if (item.isPoint()) {
            String[] ss = item.getStringPoints();
            binding.binding6.setText(ss[1]);
            binding.binding8.setText(ss[0]);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isPoint()) {
            if (item.show) {
                showView(binding.binding5, binding.binding7);
            } else {
                hideView(binding.binding5, binding.binding7);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
